<template>
  <view class="quesiton-page-mbti"
    :class="[ 'question-page-'+mbtiType]"
  >
    <navigationBar :emitBackEvent="true" @backEvent="$emit('backHandle')" :my-property="navigationBarDataInfo"/>
    <view
      class="bg-top"
      :style="{'background-image':`url(${bgTop})`}"
    >
    </view>

    <view class="main-wrapper-abs">
      <view class="main-wrapper">
        
        <view class="scl-intro"
          :style="{'paddingTop':topH+'rpx'}"
        >
          <view>{{mbtiTipInfo[0]}}</view>
          <view>{{mbtiTipInfo[1]}}</view>          
        </view>
        
        <view class="progress-wrapper" >
          <template>
            <lxProgressBar
              :backColor="progressBarSty.backColor"
              :contentColor="progressBarSty.contentColor"
              barRadius="18rpx"
              :total="100"
              barHeight="30rpx"
              :first-value="percent"
              animation
              :minWidth="0"
            />
            
          </template>
          <view class="num-wrapper"
            :style="{'background-image':`url(${staticImgs.numBg})`,'left':progressNum+'rpx'}"
          >
            {{percent}}%
          </view>
          
          <view class="gift-wrapper" v-if="showGift">
            <view style="position: relative;">
              <image :class="[{'animation-open':animationFlag}]" class="img" :src="staticImgs.gift" mode="widthFix"></image>
            </view>
          </view>
        </view>
        
        <view class="card-wrapper">
          <template v-if="staticImgs.decorate">          
            <view class="decorate-wrapper">
              <image class="img" :src="staticImgs.decorate" mode="widthFix"></image>
            </view>
            <view class="abs-dd"></view>
          </template>
          <view class="clock-wrapper">
             <image class="clock-icon" :src="staticImgs.timeIcon" mode="widthFix"></image>
              <view class="clock-text">{{countTimeStr}}</view>
          </view>
          <view class="row-1">
            <view class="col-1">问题</view>
            <view class="col-2">{{current}}</view>
            <view class="col-3">/{{max}}</view>
          </view>
          <view class="question-box">
            {{question || ''}}
          </view>
          <view class="options-warpper">
              <view 
                class="opt-item" 
                v-for="(item,index) in optnList" 
                :class="[
                  item.select&&item.select=='1'?'opt-item-act':''
                ]" 
                :key="index" 
                @click="selectAnswer(item,index)"
              >
                {{item.optnContent}}
              </view>
          </view>
          <view class="btn-group-wrapper">
            <view
              class="btn-box"
              :style="{'background-image':`url(${staticImgs.btn1})`}"
              @click="$emit('prev')"
            >
              上一题
            </view>
            <view
              class="btn-box"
              :style="{'background-image':`url(${staticImgs.btn2})`}"
              @click="$emit('go')"
            >
              目录
            </view>
            <view
              class="btn-box"
              :style="{'background-image':`url(${staticImgs.btn1})`}"
              @click="$emit('next')"
            >
              {{max==current?'提交':'下一题'}}
            </view>
          </view>
        </view>
      
      </view>
    </view>
    
    <view class="decorate-bottom" v-if="!reRenderLegend">
      <image class="img" :src="legendImg" mode="widthFix"></image>
    </view>
    
    <view
      class="bg-bottom"
      :style="{'background-image':`url(${staticImgs.bgBottom})`}"
    >
    </view>
  </view>
</template>

<script>
  import navigationBar from "@/components/navigationBar/navigationBar.vue";
  import lxProgressBar from '@/subcontractorD/components/lx-progress-bar/components/lx-progress-bar/lx-progress-bar.vue'
  var app = getApp();
  let countTimer;
  let clockTimer;
  export default {
    components:{
      navigationBar,
      lxProgressBar
    },
    props:{
      percent:{
        type:Number,
        default:0
      },
      max:{
        type:Number,
        default:0
      },
      current:{
        type:Number,
        default:0
      },
      countTime:{
        type:String,
        default:''
      },
      optnList:{
        type:Array,
        default:()=>[]
      },
      question:{
        type:String,
        default:''
      },
      showGift:{
        type:Boolean,
        default:false
      },
      mbtiType:{
        type:String,
        default:'job-mbti'
      },
      animationFlag:{
        type:Boolean,
        default:false
      },
    },
    data(){
      return {
        navigationBarDataInfo:{
        	"bg_color": "transparent",
        	"color": "#fff",
        	"flag": 1,
        	"name": "测一测",
          "hasEntity":true,
        },
        // staticImgs:{},
        staticJobImgs:{
          bgTop: this.imgBaseURL + '/scl/question-page/job-mbti/bg-top.png',
          bgBottom: this.imgBaseURL + '/scl/question-page/job-mbti/bg-bottom.png',
          btn1:this.imgBaseURL + '/scl/question-page/job-mbti/btn-1.png',
          btn2:this.imgBaseURL + '/scl/question-page/job-mbti/btn-2.png',
          decorate:this.imgBaseURL + '/scl/question-page/job-mbti/decorate.png',
          
          gift:this.imgBaseURL + '/scl/question-page/job-mbti/progree-img.png	',
          timeIcon:this.imgBaseURL + '/scl/question-page/job-mbti/time-icon.png	',
          numBg:this.imgBaseURL + '/scl/question-page/job-mbti/num-bg.png',
        },
        staticLoveImgs:{
          bgTop: this.imgBaseURL + '/scl/question-page/love-mbti/bg-top.png',
          bgBottom: this.imgBaseURL + '/scl/question-page/love-mbti/bg-bottom.png',
          btn1:this.imgBaseURL + '/scl/question-page/love-mbti/btn-1.png',
          btn2:this.imgBaseURL + '/scl/question-page/love-mbti/btn-2.png',
          decorate:this.imgBaseURL + '/scl/question-page/love-mbti/decorate.png',
          
          gift:this.imgBaseURL + '/scl/question-page/love-mbti/progree-img.png	',
          timeIcon:this.imgBaseURL + '/scl/question-page/love-mbti/time-icon.png	',
          numBg:this.imgBaseURL + '/scl/question-page/love-mbti/num-bg.png',
        },
        staticXgImgs:{
          bgTop: this.imgBaseURL + '/scl/question-page/xg-mbti/bg-top.png',
          bgBottom: this.imgBaseURL + '/scl/question-page/xg-mbti/bg-bottom.png',
          btn1:this.imgBaseURL + '/scl/question-page/xg-mbti/btn-1.png',
          btn2:this.imgBaseURL + '/scl/question-page/xg-mbti/btn-2.png',
          decorate:'',
          
          gift:this.imgBaseURL + '/scl/question-page/xg-mbti/progree-img.png	',
          timeIcon:this.imgBaseURL + '/scl/question-page/xg-mbti/time-icon.png	',
          numBg:this.imgBaseURL + '/scl/question-page/xg-mbti/num-bg.png',
        },
        // legendArr:[],
        legendJobArr:[
          this.imgBaseURL + '/scl/question-page/job-mbti/legend-1.png',
          this.imgBaseURL + '/scl/question-page/job-mbti/legend-2.png',
          this.imgBaseURL + '/scl/question-page/job-mbti/legend-3.png',
        ],
        legendLoveArr:[
          this.imgBaseURL + '/scl/question-page/love-mbti/legend-1.png',
          this.imgBaseURL + '/scl/question-page/love-mbti/legend-2.png',
          this.imgBaseURL + '/scl/question-page/love-mbti/legend-3.png',
        ],
        legendXgArr:[
          this.imgBaseURL + '/scl/question-page/xg-mbti/legend-1.png',
          this.imgBaseURL + '/scl/question-page/xg-mbti/legend-2.png',
          this.imgBaseURL + '/scl/question-page/xg-mbti/legend-3.png',
        ],
        topH:0,
        // percentNum:40,
        legendNum:0,
        reRenderLegend:false,
        selectIndex:-1,
        countTimeStr:'',
        startDateTime:0,
      }
    },
    computed:{
      progressNum(){
        if(this.percent<50){
            return this.percent*3.4 - 20
        }else{
          return this.percent*3.4
        }
      },
      legendImg(){
        let tmp = this.legendJobArr
        switch(this.mbtiType) {
          case 'job-mbti':
            tmp = this.legendJobArr
            break;
          case 'love-mbti':
            tmp = this.legendLoveArr
            break;
          case 'xg-mbti':
            tmp = this.legendXgArr
            break;
        }
        return tmp[this.legendNum]
      },
      progressBarSty(){
        let tmp
        switch(this.mbtiType) {
          case 'job-mbti':
            tmp = {
              backColor:'#2C1FA5',
              contentColor:'linear-gradient( 90deg, #B0FFE8 0%, #93D7F8 100%);',
            }
            break;
          case 'love-mbti':
            tmp = {
              backColor:'#FFFFFF',
              contentColor:'linear-gradient( 90deg, #FFA4C6 0%, #FFA4C6 100%);',
            }
            break;
          case 'xg-mbti':
            tmp = {
              backColor:'#FFFFFF',
              contentColor:'linear-gradient( 90deg, #FF9473 0%, #FFBBA5 100%);',
            }
            break;
          default:
            tmp = {
              backColor:'#2C1FA5',
              contentColor:'linear-gradient( 90deg, #B0FFE8 0%, #93D7F8 100%);',
            }
        }
        return tmp
      },
      staticImgs(){
        if(this.mbtiType == 'job-mbti'){
          return this.staticJobImgs  
        }else if(this.mbtiType == 'love-mbti'){
          return this.staticLoveImgs
        }else if(this.mbtiType == 'xg-mbti'){
          return this.staticXgImgs
        }else {
          return this.staticLoveImgs
        }
      },
      bgTop(){
        let tmp = this.staticImgs.bgTop
        switch(this.mbtiType) {
          case 'job-mbti':
            tmp = this.staticImgs.bgTop
            break;
          case 'love-mbti':
            tmp = this.staticLoveImgs.bgTop
            break;
          case 'xg-mbti':
            tmp = this.staticImgs.bgTop
            break;
        }
        return tmp
      },
      mbtiTipInfo(){
        const type = this.mbtiType || 'love-mbti'
        const tmpObj = {
          'xg-mbti':['使用人数众多的性格测试','从多个维度帮助你全面了解自己'],
          'job-mbti':['每年近300万人参与','被广泛应用于职业发展测试'],
          'love-mbti':['每年近300万人参与','被广泛应用于人格发展测试'],
        }
        return tmpObj[type]
      }
    },
    watch:{
      countTime(val){
        if(val){
          this.countTimeStr = val
        }
      },
      mbtiType:{
        handler(val){
          if(val == 'xg-mbti'){
            
            this.navigationBarDataInfo.color = 'rgba(26, 27, 31, 1)'
          }
        },
        immediate:true
      }
    },
    mounted() {
      
      this.topH = app.globalData.topHeight * 2
      countTimer = setInterval(()=>{
        this.legendNum = this.legendNum+1
        if(this.legendNum === this.legendJobArr.length){
            this.legendNum = 0
        }
        this.reRenderLegend = true
        this.$nextTick(()=>{
          this.reRenderLegend = false
        })
      },10*1000)
      // this.progressNum = 150
      // this.startDateTime = this.$dayjs()
      // clockTimer = setInterval(()=>{
      //   this.countTimeStr = this.$dayjs().subtract(this.startDateTime).format('mm:ss')
      // },1000)
    },
    beforeDestroy(){
      clearInterval(countTimer)
    },
    methods:{
      reloadClockTimer(){
        
        this.startDateTime = this.$dayjs()
        clockTimer = setInterval(()=>{
          // 00:00 这种格式
          this.countTimeStr = this.$dayjs().subtract(this.startDateTime).format('mm:ss')
        },1000)
      },
      selectAnswer(item,index){
      	this.selectIndex = index;
      	this.$emit('updateSelectSclQuestion',index);
      }
    }
  }
</script>

<style scoped lang="scss">
  @keyframes shake {
    0% {
      transform: translateX(0) translateY(0);
    }
  
    50% {
      transform: translateY(-10%);
    }
  
    100% {
      transform:translateX(0) translateY(0);
    }
  }
  
.quesiton-page-mbti,.question-page-love-mbti,.question-page-job-mbti{
  background-color: #E9E8FF;
  position: relative;
  
  // height: 100vh;
  width: 100%;
  min-height: 100vh;
  // overflow: hidden;
  height: 1580rpx;
  
  .bg-top{
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    z-index: 1;
    
    width: 750rpx;
    height: 654rpx;
    background-repeat: no-repeat;
    background-size: 100%;
  }
  
  .animation-open {
    animation: open 1.5s;
  }
  
  @keyframes open {
    0% {
      transform: scale(1) translate3d(0, 0, 0);
    }
  
    100% {
      transform: scale(4) translate3d(0, 120rpx, 0);
    }
  }
  
  .main-wrapper-abs{
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2;
    
    .main-wrapper{
      padding: 46rpx;
      padding-top: 8rpx;

      // padding-top: 10vh;
      
      position: relative;
      .progress-wrapper{
        position: relative;
        width: 400rpx;
        height: 30rpx;
        background: #2C1FA5;
        border-radius: 17rpx;
        
        .num-wrapper{
          position: absolute;
          top: -60rpx;
          width: 96rpx;
          height: 54rpx;
          
          
          background-repeat: no-repeat;
          background-size: 100%;
          font-family: PingFang-SC, PingFang-SC;
          font-weight: bold;
          font-size: 30rpx;
          color: #71FFEE;
          // line-height: 42rpx;
          text-align: center;
          font-style: normal;
          
              z-index: 999;

        }
        
        .gift-wrapper{
          position: absolute;
          right: -70rpx;
          top: -68rpx;
          height: 164rpx;
          width: 164rpx;
          
          // animation-iteration-count: infinite;
          // animation-name: shake;
          // animation-duration: 1900ms;
          // animation-delay: 0;
          // animation-timing-function: ease;
          
          .img{
            // width: 100%;
            // height: 100%;
            
            height: 164rpx;
            width: 164rpx;
            
            position: absolute;
            left: 0;
            top: 0;
            z-index: 981;
          }
        }
      }
      
      .card-wrapper{
        width: 660rpx;
        height: 880rpx;
        background: #FFFFFF;
        box-shadow: 0rpx 6rpx 20rpx 0rpx #B0B5EC;
        border-radius: 46rpx;
        box-sizing: border-box;
        padding: 26rpx 34rpx;
        margin-top: 40rpx;
        position: relative;
        
        .decorate-wrapper{
          position: absolute;
          right: 0;
          top: -240rpx;
          height: 240rpx;
          width: 224rpx;
          overflow: hidden;

          
          .img{
            width: 100%;
            height: 100%;
          }
        }
        
        .clock-wrapper{
          position: absolute;
          right: 34rpx;
          top: 34rpx;
          
          
          display: flex;
          align-items: center;
          .clock-icon{
            width: 38rpx;
            height: 38rpx;
            margin-right: 8rpx;
          }
          .clock-text{
            font-family: PingFangSC, PingFang SC;
            font-weight: 400;
            font-size: 30rpx;
            color: #999999;
            line-height: 42rpx;
            text-align: left;
            font-style: normal;
          }
        }
        
        .row-1{
          display: flex;
          align-items: center;
          margin-bottom: 30rpx;
          
            .col-1{
              font-family: PingFangSC, PingFang SC;
              font-weight: 500;
              font-size: 34rpx;
              color: #7173FF;
              // line-height: 48rpx;
              text-align: left;
              font-style: normal;
            }
            .col-2{
              margin-left: 8rpx;
              font-family: PingFangSC, PingFang SC;
              font-weight: 500;
              font-size: 40rpx;
              color: #7173FF;
              // line-height: 56rpx;
              text-align: left;
              font-style: normal;
            }
            .col-3{
              font-family: PingFangSC, PingFang SC;
              font-weight: 500;
              font-size: 20rpx;
              color: #7173FF;
              // line-height: 28rpx;
              text-align: left;
              font-style: normal;
              padding-top: 10rpx;
            }
        }
        
        .question-box{
          font-family: PingFang-SC, PingFang-SC;
          font-weight: 800;
          font-size: 32rpx;
          color: #333333;
          line-height: 54rpx;
          text-align: justify;
          font-style: normal;
          margin-bottom: 30rpx;
        }
        
        .options-warpper{
          display: flex;
          flex-direction: column;
          row-gap: 30rpx;
          overflow-y: scroll;
          
          .opt-item{
            width: 593rpx;
            // height: 90rpx;
            background: #F5F5F5;
            border-radius: 8rpx;
            
            font-family: PingFang-SC, PingFang-SC;
            font-weight: 800;
            font-size: 28rpx;
            color: #333333;
            // line-height: 90rpx;
            text-align: left;
            font-style: normal;
            padding: 24rpx 26rpx;
            box-sizing: border-box;
            
          }
          
          .opt-item-act{
            color: #FFFFFF;
            background: linear-gradient( 90deg, #575AFF 0%, #9CA2FF 100%);
          }
        }
        
        
        .btn-group-wrapper{
          position: absolute;
          bottom: 30rpx;
          left: 24rpx;
          right: 24rpx;
          
          display: flex;
          justify-content: space-between;
          column-gap: 20rpx;
          
          .btn-box{
            width: 190rpx;
            height: 90rpx;
            
            background-repeat: no-repeat;
            background-size: 100%;
            
            font-family: PingFangSC, PingFang SC;
            font-weight: 500;
            font-size: 32rpx;
            color: #FFFFFF;
            line-height: 90rpx;
            text-align: center;
            text-align: center;
            font-style: normal;
          }
          
        }
      }
      
      .scl-intro{
        font-family: PingFangSC, PingFang SC;
        font-weight: 400;
        font-size: 28rpx;
        color: #FFFFFF;
        line-height: 40rpx;
        text-align: left;
        font-style: normal;
        
        margin-bottom: 72rpx;
      }
    }
  }
  
  
  @keyframes showDivAni{
  	0%{opacity:0;}
  	100%{opacity: 1;}	
  }
  
  .decorate-bottom{
    // width: 750rpx;
    position: absolute;
    z-index: 2;

    height: 340rpx;
    bottom: 0;
    left: 0;
    right: 0;
    
    animation:showDivAni .8s 1;
    .img{
      width: 100%;
    }
    pointer-events: none;
  }
  
  .bg-bottom{
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
    
    width: 750rpx;
    height: 800rpx;
    background-repeat: no-repeat;
    background-size: 100%;
    position: absolute;
  }
}

.question-page-love-mbti{
  background-color: #FFE8F6;
  
  .main-wrapper{
    
    .scl-intro{
      color: #510951 !important;
    }
    
    .progress-wrapper{
      // box-shadow: 0rpx 6rpx 20rpx 0rpx #FFDAF3 !important;
      
      .num-wrapper{
        color: #FFFFFF !important;
      }
    }
    
    .card-wrapper{
      box-shadow: 0rpx 6rpx 20rpx 0rpx #FFDAF3 !important;
      .row-1{
        .col-1,.col-2,.col-3{
          color: #FF8BDB !important;
        }
      }
      .opt-item-act{
        background: linear-gradient( 90deg, #FF8DB8 0%, #FFC0DB 100%) !important;
      }
      
      .decorate-wrapper{
        top:-196rpx !important;
        height: 206rpx !important;
      }
      .abs-dd{
        position: absolute;
        right: 0;
        top: 0;
        height: 30rpx;
        width: 200rpx;
        border-radius: 0 46rpx;

        background-color: #fff;
        z-index: 2;
      }
    }
    
  }
}

.question-page-xg-mbti{
  background-color: rgba(255, 226, 208, 1);
  
  .bg-top{
    height: 780rpx;
  }
  
  .main-wrapper{
    
    .scl-intro{
      color: rgba(134, 51, 25, 1) !important;
    }
    
    .progress-wrapper{
      // box-shadow: 0rpx 6rpx 20rpx 0rpx #FFDAF3 !important;
      
      .num-wrapper{
        color: #FFFFFF !important;
      }
    }
    
    .card-wrapper{
      box-shadow: 0rpx 6rpx 20rpx 0rpx #FFDAF3 !important;
      .row-1{
        .col-1,.col-2,.col-3{
          color: rgba(255, 140, 48, 1) !important;
        }
        margin-bottom: 4rpx !important;
      }
      .opt-item-act{
        background: linear-gradient( 90deg, #FF8C69 0%, #FFC57B 100%) !important;
      }
      
      .options-warpper{
        row-gap: 20rpx !important;
      }
    }
  }
}
</style>